package edu.sctu.practice.class02.hujie.cgs.assign03.Two;

import java.lang.Object;

/**
 * Created by hj on 2015/11/3.
 */
public class TestInterface {
    public static void main(String[] args) {
        ComparableCircle circle1 = new ComparableCircle(5);
        ComparableCircle circle2 = new ComparableCircle(4);
        Comparable circle = Max.max(circle1, circle2);
        System.out.println("The max circle's radius is:" + ((Circle) circle).getRadius());
        System.out.println(circle);
        ComparableCylinder cylinder1 = new ComparableCylinder(5, 2);
        ComparableCylinder cylinder2 = new ComparableCylinder(4, 5);
        Comparable cylinder = Max.max(cylinder1, cylinder2);
        System.out.println();
        System.out.println("cylinder1's Volume is:" + cylinder1.findVolume());
        System.out.println("cylinder2's Volume is:" + cylinder2.findVolume());
        System.out.println("The max cylinder's\tradius is:" +
                ((Cylinder) cylinder).getRadius() +
                "\n\t\t\tlength is:" + ((Cylinder) cylinder).getLength() +
                "\n\t\t\tvolume is:" + ((Cylinder) cylinder).findVolume());
    }
}

class ComparableCircle extends Circle implements Comparable {
    public ComparableCircle(double r) {
        super(r);
    }

    public int compareTo(Object o) {
        if (getRadius() > ((Circle) o).getRadius())
            return 1;
        else if (getRadius() < ((Circle) o).getRadius())
            return 1;
        else return 0;

    }
}

class ComparableCylinder extends Cylinder implements Comparable {
    ComparableCylinder(double r, double l) {
        super(r, l);
    }

    public int compareTo(Object o) {
        if (findVolume() > ((Cylinder) o).findVolume())
            return 1;
        else if (findVolume() < ((Cylinder) o).findVolume())
            return -1;
        else return 0;
    }
}
